﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;


namespace BMUpload.Utility
{
    //扩展类
    public static class ExtendHelper
    {
        /// <summary>
        /// 扩展字典类，直接获取字典值
        /// </summary>
        /// <param name="dict"></param>
        /// <param name="sData"></param>
        /// <returns></returns>
        public static string GetDictValue(this Dictionary<string, string> dict, string sData)
        {
            string sValue = "";
            dict.TryGetValue(sData, out sValue);
            return sValue;
        }

        public static bool Validate(this DataSet ds)
        {
            bool istrue;
            if (ds == null)
            { istrue = false; }
            else if (ds.Tables.Count <= 0)
            { istrue = false; }
            else
            { istrue = true; }
            return istrue;
        }
        public static bool Validate(this DataTable dt)
        {
            bool istrue;
            if (dt == null)
            { istrue = false; }
            else if (dt.Rows.Count <= 0)
            {
                istrue = false; 
            }
            else
            { istrue = true; }
            return istrue;
        }

        public  static bool LeftIs(this string str, string sSub)
        {
            try
            {
                return str.Substring(0, sSub.Length) == sSub;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public static bool RightIs(this string str, string sSub)
        {
            try
            { 
                int startindex=str.Length-sSub.Length;
                
                return str.Substring(startindex,sSub.Length) == sSub;
            }
            catch (Exception)
            {
                return false;
            }
        }

        /// <summary>
        /// 判断object为Null返回""
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static string Nullstr(this object obj)
        {
            if (obj == null)
            {
                return "";
            }
            else
            {
                return obj.ToString();
            }
        }
    }
}
